require 'time'
require_relative '../header/header'

module Azure
  module DocumentDB
    class SecureHeader
      def initialize token, resource_type 
        self.token = token
        self.resource_type = resource_type
      end

      def header verb, resource_link = ''
        time = httpdate
        signed_auth = signed_auth time, verb, resource_link
        #hash = { 'x-ms-date' => "Tue, 26 Sep 2017 09:15:53 GMT", 'authorization' => "type%3dmaster%26ver%3d1.0%26sig%3dcYOJBcT82VoNggJ7dnJEcMZ48ir%2fLXs45cTUWvzxElY%3d" , "accept" => "application/json" }
        hash = { 'x-ms-date' => time, 'authorization' => signed_auth , "accept" => "application/json" }
        Azure::DocumentDB::Header.new.generate ['x-ms-version' ], hash
      end

      private

      attr_accessor :token, :resource_type , :time

      def signed_auth time, verb, resource_link 
        token.generate verb, resource_type, resource_link, time
      end

      def httpdate
        Time.now.httpdate
      end
    end
  end
end
